|
|
|
|
|
|
|
OLE, which stands for object linking and embedding, was introduced as a way to integrate the Microsoft Office family of products. Applications that support OLE allow users to use one application from within another without leaving the context of the original program's interface. The Microsoft Office suite is a stellar example of a group of individual programs that use OLE to work together. This capability makes a software suite much more than just a group of programs that are packaged together. |
|
|
|
|
|
|
|
|
For example, by using OLE, you can embed an Excel spreadsheet in a Word document. A user working on that Word document can edit the spreadsheet by simply double-clicking it. This action opens Excel functionality while still working in Word. |
|
|
|
|
|
|
|
|
The benefits to users include the ability to edit different types from a single, unified user interface. A benefit for programmers is that the Office applications contain a great set of exposed OLE (or ActiveX) objects that you can access from Visual Basic. Visual Basic also provides you with a very nice OLE Container control, which makes it very easy to give your users access to OLE-compliant applications from within your VB programs. |
|
|
|
|
|
|
|
|
When you use Office's OLE objects in Visual Basic, you are essentially "remote controlling" Word or Excel. This means that not only must the applications be installed on a user's machine, but your application acts just as though a user were entering and typing the commands. The application loads, and depending on how you write your VB code, users may be able to watch or interact with it. For these reasons, OLE automation may be slow, but it is still useful in some circumstances. |
|
|
|
|
|
|
|
|
The following are some advantages of using OLE automation: |
|
|
|
|
|
|
|
|
Professional-looking reports. Word and Excel can produce some nice printed reports. By driving Word and Excel remotely from VB, you can easily print reports using these programs' advanced formatting capabilities. |
|
|
|
|
|
|
|
|
Automated document creation. You can create documents and spreadsheets from VB code. For example, you can create a weekly summary of available job openings from a database and email it to prospective applicants. |
|
|
|
|
|
|
|
|
Information retrieval. You can use OLE objects in Visual Basic to extract information from an Excel spreadsheet and store it in a database. |
|
|
|
|
|
|
|
|
In this chapter, you examine some of the ways to use Word and Excel from Visual Basic. Although the examples in this chapter will use standard Visual Basic, note that Office applications now practically have Visual Basic built in, so much of the same code described here can be included as VBA code in the document or worksheet itself. |
|
|
|
|
|
|
|
|
Working with Word Objects |
|
|
|
|
|
|
|
|
The capability of controlling an instance of Microsoft Word from within a Visual Basic program can lead to some powerful added value for your applications. Users will appreciate being able to edit a Word document without having to leave a specialized program. In this section, you learn how to add Word functionality to your programs. |
|
|
|
|
|